package com.cmnit.analysis.service

import com.cmnit.analysis.dao.{EnTollDao, ExTollDao}
import com.cmnit.analysis.util.{ConfigurationManager, ServiceUtil}
import org.apache.log4j.Logger
import org.apache.spark.sql.DataFrame

class ExTollService {
  private val logger: Logger = Logger.getLogger(this.getClass)
  private val dao = new ExTollDao

  def service(acctTime: String): DataFrame = {
    // 获取加工账期（默认当前时间的前一小时）
    val sqlTime = ServiceUtil.getAcctInfo(acctTime)
    logger.info("加工账期时间：" + acctTime)

    // 注册UDF函数
    dao.registerUDF("getVehiclePlateMD5")
    logger.info("注册UDF函数：getVehiclePlateMD5")

    // 删除需要插入的账期数据
    dao.delete(ConfigurationManager.getProperty("extoll.table"), ConfigurationManager.getProperty("extoll.time"), acctTime)

    // 生成结果数据DataFrame
    dao.exTollData(sqlTime, acctTime)
  }
}